/** * Function to alert dialog */ var opt = ''; function showAlertDialog(title, message, width) { if (typeof title == "undefined" || title == "") { title = "Alert"; } $("#alertDialog").html(message); if (typeof width == "undefined" || width == '') { width = '800px'; } $("#alertDialog").dialog({ title: title, width: width, }); $("#alertDialog").dialog("open"); return false; } /** * Function to confirn delete entry from grid */ function deleteEntryConfirm(dialogId, confirmTitle, deleteMessage, deleteUrl, gridId, opt) { var name = ""; if (deleteMessage.length != 0) { if ($.trim(opt) != '') { deleteMessage = delete_confirmation1; } else { deleteMessage = delete_confirmation; } name = unescape(deleteUrl.split('?name=')[1]); name = name.split('&')[0]; } else { deleteMessage = delete_confirmation; name = unescape(deleteUrl.split('?name=')[1]); if (name == 'undefined') { name = unescape(deleteUrl.split('&name=')[1]); } } // console.log(name); name = name.replace(/\+/g, ' '); //console.log(name); deleteMessage = deleteMessage.replace('{field}', name); if (deleteUrl.indexOf('deleteable') != -1) { var deleteStatus = unescape(deleteUrl.split('&deleteable=')[1]); if (deleteStatus == false_status) { showAlertDialog("Alert", name + " is not deletable."); return false; } } $("#" + dialogId).html(deleteMessage); $("#" + dialogId).dialog({ title: confirmTitle, width: '50%' }); $("#" + dialogId).dialog("option", "buttons", { "Ok": function() { switch (gridId) { case 'parameters-grid': deleteParameter(dialogId, name, deleteUrl, gridId); break; case 'rule-grid': deleteRule(dialogId, name, deleteUrl); break; case 'user-grid': if (deleteUrl.indexOf('changeStatus') > -1) { changeUserStatus(dialogId, name, deleteUrl); } else deleteUser(dialogId, name, deleteUrl); break; case 'parameter-value-delete': $(deleteUrl).remove(); updateRowLabel(); $("#" + dialogId).dialog("close"); break; case 'disb-struc-grid': if ($.trim(opt) != '') { opt.parent().parent().parent().remove(); } deleteGridRow(dialogId, deleteUrl, gridId); break; default: deleteGridRow(dialogId, deleteUrl, gridId); $(this).dialog("close"); break; } }, "Cancel": function() { $(this).dialog("close"); }, }); $("#" + dialogId).dialog("open"); return false; } function deleteEntryConfirmAgencyAllocate(dialogId, confirmTitle, deleteMessage, deleteUrl, gridId, opt) { var name = ""; if (deleteMessage.length != 0) { if ($.trim(opt) != '') { deleteMessage = delete_confirmation1; } else { deleteMessage = delete_confirmation; } name = unescape(deleteUrl.split('?name=')[1]); name = name.split('&')[0]; } else { deleteMessage = delete_confirmation; name = unescape(deleteUrl.split('?name=')[1]); if (name == 'undefined') { name = unescape(deleteUrl.split('&name=')[1]); } } name = name.replace("+", " "); // deleteMessage = "Are you sure you want to remove allocation of agency {field} from this project?"; deleteMessage = deleteMessage.replace('{field}', name); deleteMessage = deleteMessage.replace("+", " "); if (deleteUrl.indexOf('deleteable') != -1) { var deleteStatus = unescape(deleteUrl.split('&deleteable=')[1]); if (deleteStatus == false_status) { showAlertDialog("Alert", name + " is not deletable."); return false; } } $("#" + dialogId).html(deleteMessage); $("#" + dialogId).dialog({ title: confirmTitle, width: '50%' }); $("#" + dialogId).dialog("option", "buttons", { "Ok": function() { switch (gridId) { case 'parameters-grid': deleteParameter(dialogId, name, deleteUrl, gridId); break; case 'rule-grid': deleteRule(dialogId, name, deleteUrl); break; case 'user-grid': if (deleteUrl.indexOf('changeStatus') > -1) { changeUserStatus(dialogId, name, deleteUrl); } else deleteUser(dialogId, name, deleteUrl); break; case 'parameter-value-delete': $(deleteUrl).remove(); updateRowLabel(); $("#" + dialogId).dialog("close"); break; case 'disb-struc-grid': if ($.trim(opt) != '') { opt.parent().parent().parent().remove(); } deleteGridRow(dialogId, deleteUrl, gridId); break; default: deleteGridRow(dialogId, deleteUrl, gridId); $(this).dialog("close"); break; } }, "Cancel": function() { $(this).dialog("close"); }, }); $("#" + dialogId).dialog("open"); return false; } /** * * Function to delete row */ function deleteGridRow(dialogId, deleteUrl, gridId) { $.ajax({ type: 'POST', url: deleteUrl, dataType: 'json', success: function(data) { $('.alert').each(function() { $(this).alert('close'); }); $("#" + dialogId).dialog("close"); $.fn.yiiGridView.update(gridId); var messageHtml = grid_ajax_message; messageHtml = messageHtml.replace('{message}', data.message); if (data.status == true_status) { messageHtml = messageHtml.replace('{class}', 'success'); } else { messageHtml = messageHtml.replace('{class}', 'error'); } $('#' + gridId + '-message').html(messageHtml); $('#' + gridId + '-message').show(); hideAlertDiv(gridId + '-message'); if(data.reload) { if(data.reload==1) { location.reload(); } } } }); } /** * Function set focus on first error field in form * @returns {undefined} */ function focusFirstErrField() { var errCount = 0; var elemntCount = 0; var eleMnt = ''; var firstEle = ''; $('.form [rel="tipsy"]').each(function() { if (elemntCount == 0) { firstEle = $(this); } elemntCount++; }); $('.form [rel="tipsy"]').each(function() { if (typeof $(this).attr('original-title') != "undefined" && $(this).attr('original-title') != "") { if (errCount == 0) { eleMnt = $(this); var elemntOffset = eleMnt.offset().top * (-1); var firstElemntOffset = firstEle.offset().top * (-1); var diffOffset = firstElemntOffset - elemntOffset; // $('.area').slimScroll({ // scrollTo: diffOffset, // }); setTimeout(function() { eleMnt.focus(); }, 500); } errCount++; } }); } function focusAllErrField() { setTimeout(function() { // Do something after 1 second var errCount = 0; var elemntCount = 0; var eleMnt = ''; var firstEle = ''; $('.tipsy-form [rel="tipsy"]').each(function() { if (typeof $(this).attr('original-title') != "undefined" && $(this).attr('original-title') != "") { eleMnt = $(this); eleMnt.tipsy('show'); } }); } , 100); } function focusAllErrDialogField(form) { setTimeout(function() { // Do something after 1 second var errCount = 0; var elemntCount = 0; var eleMnt = ''; var firstEle = ''; $('#' + form + ' [rel="tipsy"]').each(function() { if (typeof $(this).attr('original-title') != "undefined" && $(this).attr('original-title') != "") { eleMnt = $(this); eleMnt.tipsy('show'); } }); } , 100); setTimeout(function() { // Do something after 1 second var errCount = 0; var elemntCount = 0; var eleMnt = ''; var firstEle = ''; $('#' + form + ' [rel="tipsy"]').each(function() { if (typeof $(this).attr('original-title') != "undefined" && $(this).attr('original-title') != "") { eleMnt = $(this); eleMnt.tipsy('hide'); } }); } , 3000); } /** * Function clear form fields original-title attribute * @returns {undefined} */ function clearFormValidation() { var errCount = 0; $('.form [rel="tipsy"]').each(function() { $(this).attr('original-title', ''); }); } $(document).ready(function() { intializeForm(); // $(".read-more").each(function() { // $(this).tipsy({ // html: false // }); // }); // // $('#read-more-tooltip').popover({ // 'html': false, // 'placement' : 'left' // }); }); function intializeForm() { intializeTipsy(); intializeAutoCapitalize(); $('.float_number').each(function() { $(this).bind('keypress', function(evt) { isValidFloatNumber($(this), evt); }); $(this).bind('paste', function(evt) { isValidFloatNumber($(this), evt); }); }); $('.integer').each(function() { $(this).bind('keypress', function(evt) { isValidNumber($(this), evt); }); $(this).bind('paste', function(evt) { isValidNumber($(this), evt); }); }); $('.dateField').each(function() { $(this).attr('readonly', 'readonly'); }); } function intializeDialogForm(form_id) { var elementCount = 0; $('#' + form_id + ' [rel="tipsy"]').each(function() { var field = $(this); bindTipsyToField(field, true); elementCount++; }); focusAllErrDialogField(form_id) } /** * * Function to auto captitalize field */ function intializeAutoCapitalize() { $('.autoCapitalize').bind('keyup', function(e) { $(this).val($(this).val().toUpperCase()); }); } /** * Function to check is valid integer * */ function isValidNumber(element, evt) { if (evt.type == 'paste') { setTimeout(function(e) { element.val(''); }, 0); return false; } var charCode = (evt.which) ? evt.which : event.keyCode; if (charCode > 31 && (charCode < 48 || charCode > 57)) { showAlertDialog("Alert", "Please enter Valid Number."); return false; } else { return true; } } /** * Function to check is valid float number * */ function isValidFloatNumber(element, evt) { if (evt.type == 'paste') { setTimeout(function(e) { element.val(''); }, 0); return false; } var charCode = (evt.which) ? evt.which : event.keyCode; if (charCode > 31 && (charCode < 48 || charCode > 57) && charCode != 46) { showAlertDialog("Alert", "Please enter Valid Number."); return false; } else { var val = $(element).val(); if (charCode == 46 && val.indexOf('.') != -1) { showAlertDialog("Alert", "Please enter Valid Number."); return false; } return true; } } /** * * Function to intialize tipsy validation */ var tipsySetting = {trigger: 'focus', gravity: 'ne', fade: true}; var tipsyDialogSetting = {trigger: 'focus', gravity: 'ne', fade: true, className: 'tipsy-dialog'}; function intializeTipsy() { var elementCount = 0; $('.tipsy-form [rel="tipsy"]').each(function() { var field = $(this); bindTipsyToField(field, false); elementCount++; }); focusAllErrField(); showTipsyError() } /** * Function to show all tipsy error * */ function showTipsyError() { } /** * Method to bind tipsy on element * @param {type} formId * @returns {undefined} */ function bindTipsyToField(field, is_dialog) { if (!is_dialog) field.tipsy(tipsySetting); else field.tipsy(tipsyDialogSetting); field.bind('keypress', function() { field.tipsy("hide"); }); } /* * Method to disable enter key in form */ function disableFormEnter(formId) { if (typeof formId != "undefined") { formId = "#" + formId; } else { formId = window; } $(formId).keydown(function(event) { if (event.keyCode == 13) { event.preventDefault ? event.preventDefault() : event.returnValue = false; } }); } /* * Method select all parameters in rule builder */ function toCheckAll(id, child_class) { $('#' + id).click(function() { var checkStatus = $('#' + id).prop('checked'); if (checkStatus) { $('.' + child_class).each(function() { $(this).prop('checked', true); addRowHighlytClas(this); }); } else { $('.' + child_class).each(function() { $(this).prop('checked', false); addRowHighlytClas(this); }); } }); } /** * Function trim form values */ function trimFormValues(form_class) { $(form_class + ' :input').each(function() { if ($(this).val() != '' || $(this).val() != null) { $(this).val($.trim($(this).val())); if ($(this).val().indexOf('>') > -1 || $(this).val().indexOf('<') > -1) { $(this).val(''); } } }); } /** * Method to submit forms by post back request */ function submitForm(butn) { $(".modal-backdrop").show(); $(butn).attr('disabled', 'disabled'); $(butn).parents('form:first').submit(); } /** * Function to set max start date */ function setMaxStartDate(start_date, end_date) { var to_date = $("#" + end_date).datepicker("getDate"); if (to_date) { var d = new Date(to_date.getFullYear(), to_date.getMonth(), to_date.getDate()); $("#" + start_date).datepicker("option", "defaultDate", d); $("#" + start_date).datepicker("option", "maxDate", d); } } /** * Function to set min end date */ function setMinEndDate(start_date, end_date) { var from_date = $("#" + start_date).datepicker("getDate"); if (from_date) { var d = new Date(from_date.getFullYear(), from_date.getMonth(), from_date.getDate()); $("#" + end_date).datepicker("option", "defaultDate", d); $("#" + end_date).datepicker("option", "minDate", d); } } /** * Method to hide grid alert div */ function hideAlertDiv(eleId) { setTimeout(function() { $('#' + eleId).hide('slow'); }, 9000); } /** * Function to save agent */ function changePassword(elemnt, formName, salt) { var password = jQuery("#UserLogin_password").val(); jQuery("#UserLogin_password").val(Aes.Ctr.encrypt(password, salt, 256)); if (jQuery("#UserLogin_old_password").length > 0) { $('#change-password').append(''); var oldPassword = jQuery("#UserLogin_old_password").val(); jQuery("#UserLogin_old_password").val(Aes.Ctr.encrypt(oldPassword, salt, 256)); } if (jQuery("#UserLogin_confirm_password").length > 0) { var confirmPassword = jQuery("#UserLogin_confirm_password").val(); jQuery("#UserLogin_confirm_password").val(Aes.Ctr.encrypt(confirmPassword, salt, 256)); } var form = $(elemnt).parents('form:first'); form.submit(); } function pincodeDeleteConfirm(dialogId, confirmTitle, where, className) { var checkCount = 0; $('.' + className).each(function() { if ($(this).find('input').attr('checked')) { checkCount++; } }); if (checkCount > 0) { $("#" + dialogId).html("Selected rows will be deleted permanently. Would you like to proceed?"); $("#" + dialogId).dialog({ title: confirmTitle, width: '50%' }); $("#" + dialogId).dialog("option", "buttons", { "Ok": function() { submitForm(where); }, "Cancel": function() { $(this).dialog("close"); }, }); $("#" + dialogId).dialog("open"); return false; } else { $("#" + dialogId).html("Please select row to be deleted."); $("#" + dialogId).dialog({ title: "Error", width: '50%' }); $("#" + dialogId).dialog("option", "buttons", { "Ok": function() { $(this).dialog("close"); }, }); $("#" + dialogId).dialog("open"); // return false; } } function disbDeleteConfirm(dialogId, confirmTitle, where) { $("#" + dialogId).html("Selected pincodes will be deleted permanently. Would you like to proceed?"); $("#" + dialogId).dialog({ title: confirmTitle, width: '50%' }); $("#" + dialogId).dialog("option", "buttons", { "Ok": function() { submitForm(where); }, "Cancel": function() { $(this).dialog("close"); }, }); $("#" + dialogId).dialog("open"); return false; } /** * Method to redirect to window location */ function goToUrl(url) { window.location = web_app_url + url; } /** * Method to submit file upload */ function submitProjDocUpload() { $('#file-upload-submit-form').submit(); } function hideDiv(ele) { $(ele).addClass('displayN'); } /** * Method to return multidimensional array format for a given json object */ function getJsonArrFormat(jsonStr) { var arr = []; $.each(jsonStr, function(label, value) { arr[label] = [] $.each(value, function(key, value) { arr[label][key] = value; }); }); return arr; } function aesSubmit() { var passwordVal = $('#LoginForm_password').val(); if (passwordVal != "") { passwordVal = Aes.Ctr.encrypt(passwordVal, '', 256); $('#LoginForm_password').val(passwordVal); } return true; } function aesSubmit1() { var passwordVal = $('#LoginForm_password1').val(); console.log('123456'); if (passwordVal != "") { passwordVal = Aes.Ctr.encrypt(passwordVal, '', 256); $('#LoginForm_password1').val(passwordVal); } return true; } $('input').attr('autocomplete', 'off');